package com.example.common.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
@Schema(description="结果封装类")
public class Result<T>{

    public static final int SUCCESS_CODE  = 200;
    public static final int CLIENT_FAIL_CODE = 400;
    public static final int SERVICE_FAILED_CODE = 500;

    @Schema(description="状态码")
    private int code;

    @Schema(description="提示信息")
    private String msg;

    @Schema(description="数据")
    private T data;

    private Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(SUCCESS_CODE, "success", data);
    }

    public static <T> Result<T> clientFail(String msg, T data) {
        return new Result<>(CLIENT_FAIL_CODE, msg, data);
    }

    public static <T> Result<T> serviceFail(String msg , T data) {
        return new Result<>(SERVICE_FAILED_CODE, msg, data);
    }

    public static <T> Result<T> fail(int code, String msg, T data) {
        return new Result<>(code, msg, data);
    }

}
